<template>
  <page-view :avatar="avatar" :title="false">
    <div slot="headerContent">
      <div class="title">{{ timeFix }}，{{ nickname }}<span class="welcome-text">，{{ welcome }}</span></div>
      <div>wangsd | 致力于打造最方便快捷的内网穿透, 感谢您的支持!</div>
    </div>
    <div slot="extra">
      <a-row class="more-info">
        <a-col :span="8">
          <head-info title="项目" content="56" :center="false" :bordered="false"/>
        </a-col>
        <a-col :span="8">
          <head-info title="团队排名" content="8/24" :center="false" :bordered="false"/>
        </a-col>
        <a-col :span="8">
          <head-info title="项目数" content="2,223" :center="false"/>
        </a-col>
      </a-row>
    </div>

    <div>
      <a-row :gutter="24">
        <a-col :xl="16" :lg="24" :md="24" :sm="24" :xs="24">
          <a-card
            class="project-list"
            style="margin-bottom: 24px;"
            :bordered="false"
            title="进行中的项目"
            :body-style="{ padding: 0 }">
            <!--<a slot="extra">全部项目</a>-->
            <div>
              <a-card-grid class="project-card-grid">
                <a-card :bordered="false" :body-style="{ padding: 0 }">
                  <a-card-meta>
                    <div slot="title" class="card-title">
                      <a-avatar size="small" src="/top1.png"/>
                      <a>试用版本</a>
                    </div>
                    <div slot="description" class="card-description">
                      该版本仅作为功能测试，感谢您的支持
                    </div>
                  </a-card-meta>
                  <div class="project-item">
                    <span class="datetime">试用版，功能测试</span>
                  </div>
                </a-card>
              </a-card-grid>
              <a-card-grid class="project-card-grid">
                <a-card :bordered="false" :body-style="{ padding: 0 }">
                  <a-card-meta>
                    <div slot="title" class="card-title">
                      <a-avatar size="small" src="/top2.png"/>
                      <a>[高性能] 多线路3Mb</a>
                    </div>
                    <div slot="description" class="card-description">
                      【免费提供SSL】3Mbps带宽，支持断线重连、
                    </div>
                  </a-card-meta>
                  <div class="project-item">
                    <span class="datetime">IO优化，超强稳定</span>
                  </div>
                </a-card>
              </a-card-grid>
              <a-card-grid class="project-card-grid">
                <a-card :bordered="false" :body-style="{ padding: 0 }">
                  <a-card-meta>
                    <div slot="title" class="card-title">
                      <a-avatar size="small" src="/top3.png"/>
                      <a>[高性能] 多线路1Mb</a>
                    </div>
                    <div slot="description" class="card-description">
                      【免费提供SSL】1Mbps带宽，支持断线重连、
                    </div>
                  </a-card-meta>
                  <div class="project-item">
                    <span class="datetime">断线重连，心跳机制</span>
                  </div>
                </a-card>
              </a-card-grid>
              <a-card-grid class="project-card-grid">
                <a-card :bordered="false" :body-style="{ padding: 0 }">
                  <a-card-meta>
                    <div slot="title" class="card-title">
                      <a-avatar size="small" src="/top4.png"/>
                      <a>香港CN2高速服务器</a>
                    </div>
                    <div slot="description" class="card-description">
                      【免费提供SSL】香港CN2线路高速回国，低延迟，绑定域名无需备案
                    </div>
                  </a-card-meta>
                  <div class="project-item">
                    <span class="datetime">免备案，畅快用</span>
                  </div>
                </a-card>
              </a-card-grid>
              <a-card-grid class="project-card-grid">
                <a-card :bordered="false" :body-style="{ padding: 0 }">
                  <a-card-meta>
                    <div slot="title" class="card-title">
                      <a-avatar size="small" src="/top4.png"/>
                      <a>【高性能】多线10Mbps</a>
                    </div>
                    <div slot="description" class="card-description">
                      【免费提供SSL】高性能10Mbps带宽服务器，性能强悍！
                    </div>
                  </a-card-meta>
                  <div class="project-item">
                    <span class="datetime">极致体验，高速传输</span>
                  </div>
                </a-card>
              </a-card-grid>
            </div>
          </a-card>

          <a-card title="系统公告" :bordered="false">
            <a-list>

              <a-list-item>
                <a-list-item-meta>
                  <!--<a-avatar slot="avatar" :src="item.user.avatar" />-->
                  <div slot="title">
                    <!--<span>小米</span>-->
                    <a href="#">签名说明</a>
                  </div>
                  <div slot="description">
                    所有参与签名的字段按照ascii码从小到大排序加上&key=商户密钥（即key1=value1&key2=value2&key=商户密钥）<br>
                    签名串为md5小写
                  </div>
                </a-list-item-meta>
              </a-list-item>

              <a-list-item>
                <a-list-item-meta>
                  <!--<a-avatar slot="avatar" :src="item.user.avatar" />-->
                  <div slot="title">
                    <!--<span>小米</span>-->
                    <a href="#">创建订单</a>
                  </div>
                  <div slot="description">
                    接口地址：http://47.108.136.14:50001/api/open/createOrder<br>
                    请求方式Content-Type：application/x-www-form-urlencoded; charset=UTF-8<br>
                    请求参数说明：<table border="1">
                      <tr><td>商户号</td><td>customerNo</td><td><b>参与签名</b></td></tr>
                      <tr><td>商户订单号</td><td>outTradeNo</td><td><b>参与签名</b></td></tr>
                      <tr><td>回调地址</td><td>notifyUrl</td><td><b>参与签名</b></td></tr>
                      <tr><td>支付标识</td><td>payCode</td><td><b>参与签名</b></td></tr>
                      <tr><td>金额(以分为单位)</td><td>amount</td><td><b>参与签名</b></td></tr>
                      <tr><td>支付类型</td><td>payType</td><td>不参与签名</td></tr>
                      <tr><td>签名</td><td>sign</td><td>不参与签名</td></tr>
                    </table>
                    返回结果：{"code":200,"message":"操作成功","result":{"pageUrl":"weixin://wxpay/bizpayurl?pr=eY2Z5hT"}}<br>
                    返回参数说明：<table border="1">
                    <tr><td>code</td><td>200表示下单成功</td></tr>
                    <tr><td>pageUrl</td><td>支付地址</td></tr>
                  </table>
                  </div>
                </a-list-item-meta>
              </a-list-item>

              <a-list-item>
                <a-list-item-meta>
                  <!--<a-avatar slot="avatar" :src="item.user.avatar" />-->
                  <div slot="title">
                    <!--<span>小米</span>-->
                    <a href="#">异步通知回调</a>
                  </div>
                  <div slot="description">
                    通知方式：HTTP POST<br>
                    收到通知后请回复：success<br>
                    参数说明：<table border="1">
                    <tr><td>商户订单号</td><td>outTradeNo</td><td><b>参与签名</b></td></tr>
                    <tr><td>交易单号</td><td>transactionId</td><td><b>参与签名</b></td></tr>
                    <tr><td>支付标识</td><td>payCode</td><td><b>参与签名</b></td></tr>
                    <tr><td>金额(以分为单位)</td><td>amount</td><td><b>参与签名</b></td></tr>
                    <tr><td>状态(1标识成功,其他失败)</td><td>status</td><td><b>参与签名</b></td></tr>
                    <tr><td>签名</td><td>sign</td><td>不参与签名</td></tr>
                  </table>
                  </div>
                </a-list-item-meta>
              </a-list-item>
            </a-list>
          </a-card>
        </a-col>

        <a-col
          style="padding: 0 12px"
          :xl="8"
          :lg="24"
          :md="24"
          :sm="24"
          :xs="24">
          <a-card title="快速开始 / 便捷导航" style="margin-bottom: 24px" :bordered="false" :body-style="{padding: 0}">
            <div class="item-group">
              <a>操作一</a>
              <a>操作二</a>
              <a>操作三</a>
              <a>操作四</a>
              <a>操作五</a>
              <a>操作六</a>
              <a-button size="small" type="primary" ghost icon="plus">添加</a-button>
            </div>
          </a-card>

          <a-card title="修改登陆密码" style="margin-bottom: 24px" :bordered="false" :body-style="{ padding: 20 }">
            <div style="min-height: 200px;">
              <a-form :form="form">
                <a-form-item>
                  <a-input
                    type="password"
                    placeholder="原始登陆密码"
                    v-decorator="['oldPass', {rules: [{ required: true, message: '请输入' }] }]"
                  ></a-input>
                </a-form-item>

                <a-form-item>
                  <a-input
                    type="password"
                    placeholder="新密码"
                    v-decorator="['password', {rules: [{ required: true, message: '请输入'}] }]"
                  ></a-input>
                </a-form-item>

                <a-form-item>
                  <a-input
                    type="password"
                    placeholder="确认密码"
                    v-decorator="['password2', {rules: [{ required: true, message: '请输入' }, { validator: this.handlePasswordCheck }], validateTrigger: ['change', 'blur']}]"
                  ></a-input>
                </a-form-item>

                <a-form-item style="margin-bottom: 0px">
                  <a-button
                    type="primary"
                    htmlType="submit"
                    :loading="registerBtn"
                    @click.stop.prevent="handleSubmit"
                    :disabled="registerBtn">修改
                  </a-button>
                </a-form-item>

              </a-form>
            </div>
          </a-card>
          <a-card title="留言板" :bordered="false">
            <div class="members">
              <a-textarea placeholder="留言板" :rows="4"/>
              <a-button type="primary" style="margin-top: 20px;">提交</a-button>
            </div>
          </a-card>
        </a-col>
      </a-row>
    </div>
  </page-view>
</template>

<script>
  import { timeFix } from '@/utils/util'
  import { mapState } from 'vuex'

  import { PageView } from '@/layouts'
  import HeadInfo from '@/components/tools/HeadInfo'
  import { Radar } from '@/components'
  import { updatePassword } from '@/api/system/user'

  const DataSet = require('@antv/data-set')

  const levelNames = {
    0: '低',
    1: '低',
    2: '中',
    3: '强'
  }
  const levelClass = {
    0: 'error',
    1: 'error',
    2: 'warning',
    3: 'success'
  }
  const levelColor = {
    0: '#ff0000',
    1: '#ff0000',
    2: '#ff7e05',
    3: '#52c41a'
  }
  export default {
    name: 'Workplace',
    components: {
      PageView,
      HeadInfo,
      Radar
    },
    data () {
      return {
        timeFix: timeFix(),
        avatar: '/avatar2.jpg',
        user: {},

        form: this.$form.createForm(this),

        state: {
          time: 60,
          smsSendBtn: false,
          passwordLevel: 0,
          passwordLevelChecked: false,
          percent: 10,
          progressColor: '#FF0000'
        },
        registerBtn: false
      }
    },
    computed: {
      ...mapState({
        nickname: (state) => state.user.name,
        welcome: (state) => state.user.welcome
      }),
      passwordLevelClass () {
        return levelClass[this.state.passwordLevel]
      },
      passwordLevelName () {
        return levelNames[this.state.passwordLevel]
      },
      passwordLevelColor () {
        return levelColor[this.state.passwordLevel]
      }
    },
    created () {
    },
    mounted () {

    },
    methods: {
      handlePasswordInputClick () {
        if (!this.isMobile()) {
          this.state.passwordLevelChecked = true
          return
        }
        this.state.passwordLevelChecked = false
      },
      handleSubmit () {
        this.registerBtn = true
        const { form: { validateFields }, state, $router } = this
        validateFields({ force: true }, (err, values) => {
          if (!err) {
            updatePassword(values).then((res) => {
              this.registerBtn = false
              this.form.resetFields()
              if (res.code === 200) {
                this.$message.success(res.message)
              }
            })
          } else {
            this.registerBtn = false
          }
        })
      },
      handlePasswordLevel (rule, value, callback) {
        let level = 0

        // 判断这个字符串中有没有数字
        if (/[0-9]/.test(value)) {
          level++
        }
        // 判断字符串中有没有字母
        if (/[a-zA-Z]/.test(value)) {
          level++
        }
        // 判断字符串中有没有特殊符号
        if (/[^0-9a-zA-Z_]/.test(value)) {
          level++
        }
        this.state.passwordLevel = level
        this.state.percent = level * 30
        if (level >= 2) {
          if (level >= 3) {
            this.state.percent = 100
          }
          callback()
        } else {
          if (level === 0) {
            this.state.percent = 10
          }
          callback(new Error('密码强度不够'))
        }
      },

      handlePasswordCheck (rule, value, callback) {
        const password = this.form.getFieldValue('password')
        if (value === undefined) {
          callback(new Error('请输入密码'))
        }
        if (value && password && value.trim() !== password.trim()) {
          callback(new Error('两次密码不一致'))
        }
        callback()
      }
    }
  }
</script>

<style lang="less" scoped>
  .project-list {

    .card-title {
      font-size: 0;

      a {
        color: rgba(0, 0, 0, 0.85);
        margin-left: 12px;
        line-height: 24px;
        height: 24px;
        display: inline-block;
        vertical-align: top;
        font-size: 14px;

        &:hover {
          color: #1890ff;
        }
      }
    }

    .card-description {
      color: rgba(0, 0, 0, 0.45);
      height: 44px;
      line-height: 22px;
      overflow: hidden;
    }

    .project-item {
      display: flex;
      margin-top: 8px;
      overflow: hidden;
      font-size: 12px;
      height: 20px;
      line-height: 20px;

      a {
        color: rgba(0, 0, 0, 0.45);
        display: inline-block;
        flex: 1 1 0;

        &:hover {
          color: #1890ff;
        }
      }

      .datetime {
        color: rgba(0, 0, 0, 0.25);
        flex: 0 0 auto;
        float: right;
      }
    }

    .ant-card-meta-description {
      color: rgba(0, 0, 0, 0.45);
      height: 44px;
      line-height: 22px;
      overflow: hidden;
    }
  }

  .item-group {
    padding: 20px 0 8px 24px;
    font-size: 0;

    a {
      color: rgba(0, 0, 0, 0.65);
      display: inline-block;
      font-size: 14px;
      margin-bottom: 13px;
      width: 25%;
    }
  }

  .members {
    a {
      display: block;
      margin: 12px 0;
      line-height: 24px;
      height: 24px;

      .member {
        font-size: 14px;
        color: rgba(0, 0, 0, .65);
        line-height: 24px;
        max-width: 100px;
        vertical-align: top;
        margin-left: 12px;
        transition: all 0.3s;
        display: inline-block;
      }

      &:hover {
        span {
          color: #1890ff;
        }
      }
    }
  }

  .mobile {

    .project-list {

      .project-card-grid {
        width: 100%;
      }
    }

    .more-info {
      border: 0;
      padding-top: 16px;
      margin: 16px 0 16px;
    }

    .headerContent .title .welcome-text {
      display: none;
    }
  }

</style>
